package com.djakapm.markdown.editor.component;

import com.djakapm.markdown.editor.AppConstant;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class AppFileFilter extends javax.swing.filechooser.FileFilter {

    protected List<String> extension = new ArrayList<String>();

    public AppFileFilter(){
        extension.add(AppConstant.DEFAULT_INPUT_FILE_EXT);
    }

    @Override
    public boolean accept(File f) {
        if(f.isDirectory()){return true;}
        if(f.isFile()){
            for(String ext: extension){
                if(f.getName().endsWith(ext)){
                    return true;
                }
            }
        }
        return false;
    }

    @Override
    public String getDescription() {
        return AppConstant.DEFAULT_FILE_EXT_LABEL;
    }
}
